/* GUI CONVERTED from reworp3a.p (converter v1.75) Thu Oct  5 12:01:25 2000 */
/* reworp3a.p - REPETITIVE                                                 */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                     */
/* All rights reserved worldwide.  This is an unpublished work.            */
/*F0PN*/ /*V8:ConvertMode=Report                                           */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                    */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*             */
/* REVISION: 7.3      LAST MODIFIED: 08/29/95   BY: STR *G0VD*             */
/* REVISION: 8.5      LAST MODIFIED: 04/04/96   BY: GWM *J0GG*             */
/* REVISION: 8.5      LAST MODIFIED: 03/06/97   BY: *J1K8* Julie Milligan  */
/* REVISION: 8.6      LAST MODIFIED: 10/16/97   BY: gyk *K10Z*             */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane       */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan      */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan      */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte     */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb             */
/* REVISION: 9.1      LAST MODIFIED: 09/11/00   BY: *N0RQ* Mudit Mehta     */

/* WIP VALUATION REPORT SUBPROGRAM                                         */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

          {mfdeclre.i}
/*N0RQ*/  {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE reworp3a_p_2 "Mile-!stone"
/* MaxLen: Comment: */

&SCOPED-DEFINE reworp3a_p_3 "Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE reworp3a_p_5 "Cost Element"
/* MaxLen: Comment: */

&SCOPED-DEFINE reworp3a_p_6 "Extended Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE reworp3a_p_7 "Next Op Input!Queue Qty"
/* MaxLen: Comment: */

&SCOPED-DEFINE reworp3a_p_8 "WIP Value"
/* MaxLen: Comment: */

/*N0RQ***********BEGIN COMMENTING*************
 * &SCOPED-DEFINE reworp3a_p_1 "Cum Order Total"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE reworp3a_p_4 "Item Total"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE reworp3a_p_9 "Site Total"
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE reworp3a_p_10 "Total"
 * /* MaxLen: Comment: */
 *N0RQ***********END COMMENTING************* */

/* ********** End Translatable Strings Definitions ********* */

/*K10Z*/ {wbrp02.i}


/*N04H**  {rewrsdef.i}                                                        */

          define buffer next_wr_route for wr_route.
          define shared variable lot like wo_lot.
          define shared variable lot1 like wo_lot.
          define shared variable part like wo_part.
          define shared variable part1 like wo_part.
          define shared variable site like wo_site.
          define shared variable site1 like wo_site.
          define shared variable line like wo_line.
          define shared variable line1 like wo_line.
          define shared variable endeff as date.
          define shared variable report_cost_elements like mfc_logical.
          define shared variable cost_set_to_use as character.

          define variable bom_code as character.
          define variable cost_element as character format "x(15)"
             label {&reworp3a_p_5}.
          define variable cost_element_cost like iro_cost_tot
             column-label {&reworp3a_p_3}.
          define variable cur_cost_mthd as character.
          define variable cur_cost_set as character.
          define variable extd_val like trgl_gl_amt label {&reworp3a_p_8}.
          define variable gl_cost_mthd as character.
          define variable gl_cost_set as character.
          define variable next_op_input_que like wr_qty_inque
             column-label {&reworp3a_p_7}.
          define variable ord_qty like pt_ord_qty.
          define variable qty_inque as decimal.
          define variable routing as character.
          define variable total_qty as decimal.
          define variable fieldname like _field._field-name.
/*J0GG*/  define variable tablename like _file._file-name.
          define variable fieldfound as log.
          define variable fieldlabel like _field._label.
          define variable fieldcollabel like _field._col-label.
          define variable fielddatatype like _field._data-type.
          define variable fieldformat like _field._format.
          define variable fielddesc like _field._desc.
          define variable fieldvalexp like _field._valexp.
          define variable fieldvalmsg like _field._valmsg.
          define variable fieldextent like _field._extent.
          define variable mtl_ll like glt_amt.
          define variable lbr_ll like glt_amt.
          define variable bdn_ll like glt_amt.
          define variable sub_ll like glt_amt.
          define variable mtl_tl like glt_amt.
          define variable lbr_tl like glt_amt.
          define variable bdn_tl like glt_amt.
          define variable sub_tl like glt_amt.
          define variable cost_tot like glt_amt column-label {&reworp3a_p_6}.

          {mfphead.i}

          /*NOTE: LOOK AT ALL ORDERS CLOSED OR NOT*/

         mainloop:
         for each wo_mstr no-lock
         where wo_type = "c"
         and wo_lot >= lot and wo_lot <= lot1
         and wo_part >= part and wo_part <= part1
         and wo_site >= site and wo_site <= site1
         and wo_line >= line and wo_line <= line1
         and (wo_rel_date <= endeff or wo_rel_date = ?)
         and (wo_due_date >= endeff or wo_due_date = ?)
         and wo_nbr = ""
         use-index wo_type_part,
         each pt_mstr no-lock
         where pt_part = wo_part,
         each pl_mstr no-lock
         where pl_prod_line = pt_prod_line,
         each wr_route no-lock
         where wr_lot = wo_lot
         break by wo_site by wo_part
/*N0RQ*  by wo_line by wo_due_date by wo_lot by wr_op: */
/*N0RQ*/ by wo_line by wo_due_date by wo_lot by wr_op with frame f-a:

            FORM /*GUI*/ 
/*N0RQ*     with width 132. */
/*N0RQ*/    with STREAM-IO /*GUI*/  frame f-a width 132.

            /* SET EXTERNAL LABELS */
/*N0RQ*/    setFrameLabels(frame f-a:handle).

            if first-of(wo_lot) then do:
               {gprun.i ""rewodisp.p"" "(input wo_lot)"}
            end.

            /*GET NEXT OP INPUT QUEUE*/
            do for next_wr_route:
               next_op_input_que = ?.

               find first next_wr_route where wr_lot = wr_route.wr_lot
               and wr_op > wr_route.wr_op
               no-lock no-error.

               if available next_wr_route then do:
/*N04H*           {rewrsget.i &lot=wr_lot &op=wr_op &lock=no-lock}  */
                  next_op_input_que = wr_qty_inque.
               end.
            end.

/*N04H*     {rewrsget.i &lot=wr_lot &op=wr_op &lock=no-lock}        */

            total_qty = wr_qty_outque + wr_qty_rejque.
            if next_op_input_que <> ? then
               total_qty = total_qty + next_op_input_que.

            if cost_set_to_use = "1" then do:

               /*USE CUM ORDER STANDARD COST*/
               find iro_det where iro_part = wo_part
               and iro_site = wo_site
               and iro_cost_set = "cumorder"
               and iro_routing = wo_lot
               and iro_op = wr_op
/*G0VD*        no-lock. */
/*G0VD*/       no-lock no-error.

/*G0VD*/       if available iro_det then
                  cost_tot = total_qty * iro_cost_tot.
/*G0VD*/       else
                  cost_tot = 0.

            end.

            else
            if cost_set_to_use = "2" then do:

               /*USE CUM ORDER AVERAGE COST*/
               find iro_det where iro_part = wo_part
               and iro_site = wo_site
               and iro_cost_set = "cumorderavg"
               and iro_routing = wo_lot
               and iro_op = wr_op
               exclusive-lock no-error.

               if not available iro_det then do:
                  create iro_det.
                  assign
                     iro_part = wo_part
                     iro_site = wo_site
                     iro_cost_set = "cumorderavg"
                     iro_routing = wo_lot
                     iro_op = wr_op.
               end.

               lbr_ll = wr_lbr_ll_act - wr_lbr_ll_totx.
               bdn_ll = wr_bdn_ll_act - wr_bdn_ll_totx.
               sub_ll = wr_sub_ll_act - wr_sub_ll_totx.
               mtl_ll = wr_mtl_ll_act - wr_mtl_ll_totx.

               lbr_tl = wr_lbr_act - wr_lbr_totx.
               bdn_tl = wr_bdn_act - wr_bdn_totx.
               sub_tl = wr_sub_act - wr_sub_totx.
               mtl_tl = wr_mtl_act - wr_mtl_totx.

               cost_tot =
                  lbr_ll + bdn_ll + sub_ll + mtl_ll +
                  lbr_tl + bdn_tl + sub_tl + mtl_tl.

               /*UPDATE COSTS*/
               iro_lbr_ll = lbr_ll / total_qty.
               iro_bdn_ll = bdn_ll / total_qty.
               iro_sub_ll = sub_ll / total_qty.
               iro_mtl_ll = mtl_ll / total_qty.

               iro_lbr_tl = lbr_tl / total_qty.
               iro_bdn_tl = bdn_tl / total_qty.
               iro_sub_tl = sub_tl / total_qty.
               iro_mtl_tl = mtl_tl / total_qty.

               iro_cost_tot =
                  iro_lbr_ll + iro_bdn_ll + iro_sub_ll + iro_mtl_ll +
                  iro_lbr_tl + iro_bdn_tl + iro_sub_tl + iro_mtl_tl.

            end.

            else do:

               /*USE G/L COST*/
               routing = wo_part.
               bom_code = wo_part.
               if wo_routing > "" then routing = wo_routing.
               if wo_bom_code > "" then bom_code = wo_bom_code.

               {gprun.i ""csavg01.p"" "(input wo_part, input wo_site,
                  output gl_cost_set, output gl_cost_mthd,
                  output cur_cost_set, output cur_cost_mthd)"}

               find iro_det
               where iro_part = bom_code
               and iro_site = wo_site
               and iro_cost_set = gl_cost_set
               and iro_routing = routing
               and iro_op = wr_op
               no-lock no-error.

               if not available iro_det then do:
                  ord_qty = 1.

                  if pt_ord_qty <> 0 then ord_qty = pt_ord_qty.

                  find ptp_det where ptp_part = wo_part and ptp_site = wo_site
                  no-lock no-error.

                  if available ptp_det then do:
                     if ptp_ord_qty <> 0 then ord_qty = ptp_ord_qty.
                  end.

                  {gprun.i ""rwroru1a.p""
                    "(wo_site,gl_cost_set,routing,bom_code,ord_qty,today,yes)"}

                  find iro_det
                  where iro_part = bom_code
                  and iro_site = wo_site
                  and iro_cost_set = gl_cost_set
                  and iro_routing = routing
                  and iro_op = wr_op
/*G0VD*           no-lock. */
/*G0VD*/          no-lock no-error.
               end.

/*G0VD*/       if available iro_det then
                  cost_tot = total_qty * iro_cost_tot.
/*G0VD*/       else
                  cost_tot = 0.

            end.

            accumulate cost_tot
            (sub-total by wo_site by wo_part by wo_line by wo_due_date
            by wo_lot).

            display
               wr_op
               wr_desc
               wr_milestone     column-label {&reworp3a_p_2}
               wr_qty_outque
               wr_qty_rejque
               next_op_input_que when (next_op_input_que <> ?) WITH STREAM-IO /*GUI*/ .

/*G0VD*/    if available iro_det then do:
/*J1K8*/       tablename = "iro_det".
               if cost_set_to_use = "2" then do:
                  if report_cost_elements then do:
                     {reworp3b.i mtl_ll "down 1."}
                     {reworp3b.i lbr_ll "down 1."}
                     {reworp3b.i bdn_ll "down 1."}
                     {reworp3b.i sub_ll "down 1."}
                     {reworp3b.i mtl_tl "down 1."}
                     {reworp3b.i lbr_tl "down 1."}
                     {reworp3b.i bdn_tl "down 1."}
                     {reworp3b.i sub_tl "down 1."}
                     {reworp3b.i cost_tot "down 1."}
                  end.
                  else do:
                   {reworp3b.i cost_tot}
                  end.
               end.
               else do:
                  if report_cost_elements then do:
                     {reworp3a.i iro_mtl_ll "down 1."}
                     {reworp3a.i iro_lbr_ll "down 1."}
                     {reworp3a.i iro_bdn_ll "down 1."}
                     {reworp3a.i iro_sub_ll "down 1."}
                     {reworp3a.i iro_mtl_tl "down 1."}
                     {reworp3a.i iro_lbr_tl "down 1."}
                     {reworp3a.i iro_bdn_tl "down 1."}
                     {reworp3a.i iro_sub_tl "down 1."}
                     {reworp3a.i iro_cost_tot "down 1."}
                  end.
                  else do:
                   {reworp3a.i iro_cost_tot}
                  end.
               end.
/*G0VD*/    end.
/*G0VD*/    else do:
/*G0VD*/       if report_cost_elements then do:
/*G0VD*/          {reworp3c.i "down 1."}
/*G0VD*/       end.
/*G0VD*/       else do:
/*G0VD*/          {reworp3c.i}
/*G0VD*/       end.
/*G0VD*/    end.

            if last-of(wo_lot) then do:
               underline cost_tot.
               display
/*N0RQ*           {&reworp3a_p_1} @ cost_element_cost */
/*N0RQ*/          getTermLabel("CUM_ORDER_TOTAL",15) @ cost_element_cost
                  accum sub-total by wo_lot cost_tot @ cost_tot WITH STREAM-IO /*GUI*/ .
               down 1.
            end.

            if last-of(wo_part) then do:
               underline cost_tot.
               display
/*N0RQ*           {&reworp3a_p_4} @ cost_element_cost */
/*N0RQ*/          getTermLabel("ITEM_TOTAL",15) @ cost_element_cost
                  accum sub-total by wo_part cost_tot @ cost_tot WITH STREAM-IO /*GUI*/ .
               down 1.
            end.

            if last-of(wo_site) then do:
               underline cost_tot.
               display
/*N0RQ*           {&reworp3a_p_9} @ cost_element_cost */
/*N0RQ*/          getTermLabel("SITE_TOTAL",15) @ cost_element_cost
                  accum sub-total by wo_site cost_tot @ cost_tot WITH STREAM-IO /*GUI*/ .
               down 1.
            end.

            if last(wo_site) then do:
               underline cost_tot.
               display
/*N0RQ*           {&reworp3a_p_10} @ cost_element_cost */
/*N0RQ*/          getTermLabel("TOTAL",15) @ cost_element_cost
                  accum total cost_tot @ cost_tot WITH STREAM-IO /*GUI*/ .
               down 1.
            end.

            
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


         end.

/*K10Z*/ {wbrp04.i}
